package com.example.administrator.zhjt.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.administrator.zhjt.R;

import java.util.List;

/**
 * Created by Administrator on 2017/5/16 0016.
 */

public class EnvironmentAdapter extends BaseAdapter {

    private List<Bean> list;
    private Context context;

    public EnvironmentAdapter(List<Bean> list, Context context){
        this.list=list;
        this.context=context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView= LayoutInflater.from(parent.getContext()).inflate(R.layout.environment_item,null);
        TextView tv_title= (TextView) convertView.findViewById(R.id.tv_title);
        TextView tv_value= (TextView) convertView.findViewById(R.id.tv_value);
        Bean bean =list.get(position);
        tv_title.setText(bean.getTitle());
        tv_value.setText(bean.getValue()+"");
        if (position==0){
            if (bean.getValue()<10){
                tv_value.setBackgroundResource(R.drawable.round_red);
            }else if(bean.getValue()>40){
                tv_value.setBackgroundResource(R.drawable.round_red);
            }
        }
        if (position==1){
            if (bean.getValue()<40){
                tv_value.setBackgroundResource(R.drawable.round_red);
            }else if(bean.getValue()>70){
                tv_value.setBackgroundResource(R.drawable.round_red);
            }
        }
        if (position==2){
            if (bean.getValue()<3000){
                tv_value.setBackgroundResource(R.drawable.round_red);
            }else if(bean.getValue()>6000){
                tv_value.setBackgroundResource(R.drawable.round_red);
            }
        }
        if (position==3){
            if (bean.getValue()<10){
                tv_value.setBackgroundResource(R.drawable.round_red);
            }else if(bean.getValue()>120){
                tv_value.setBackgroundResource(R.drawable.round_red);
            }
        }
        if (position==4){
            if (bean.getValue()<10){
                tv_value.setBackgroundResource(R.drawable.round_red);
            }else if(bean.getValue()>100){
                tv_value.setBackgroundResource(R.drawable.round_red);
            }
        }
        if (position==5){
            if (bean.getValue()>3){
                tv_value.setBackgroundResource(R.drawable.round_red);
            }
        }
        return convertView;
    }

    public class Bean {
        private String title;
        private int value;

        public void setTitle(String title) {
            this.title = title;
        }

        public int getValue() {
            return value;
        }

        public void setValue(int value) {
            this.value = value;
        }

        public String getTitle() {
            return title;
        }
    }

}
